package com.platform.modules.sys.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.HashMap;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.platform.common.annotation.SysLog;
import com.platform.common.page.PageUtil;
import com.platform.common.utils.RestResponse;
import com.platform.modules.sys.service.SysLogService;

/**
 * 系统日志
 *
 * @author 肖亮
 */
@Api(tags = "SysLogController|系统日志管理")
@Controller
@RequestMapping("/sys/log")
public class SysLogController {
	@Autowired
	private SysLogService sysLogService;

	/**
	 * 列表
	 *
	 * @param params
	   *    查询参数
	 * @return RestResponse
	 */
	@ApiOperation(value = "分页系统日志列表", notes = "根据条件获取系统日志列表")
    @ApiImplicitParams({
	    @ApiImplicitParam(paramType = "query", name = "currPage", value = "当前页数", dataType = "Integer"),
	    @ApiImplicitParam(paramType = "query", name = "limit", value = "分页步数", dataType = "Integer"),
	    @ApiImplicitParam(paramType = "query", name = "key", value = "key值", dataType = "String")
    })
	@ResponseBody
	@PostMapping("/list")
	@RequiresPermissions("sys:log:list")
	public RestResponse list(Integer currPage,Integer limit,String key) {
		    Map<String, Object> params = new HashMap<String, Object>();
			params.put("page", PageUtil.getCurrPage(currPage));
			params.put("limit", PageUtil.getLimit(limit));
			params.put("key", key);
		    IPage page = sysLogService.queryPage(params);
		    return RestResponse.success().put("page", page);
	}

	/**
	    * 系统日志删除
	 *
	 * @param keys
	 *            keys
	 * @return RestResponse
	 */
	@ApiOperation(value = "系统日志删除", notes = "根据ID删除系统日志（支持多ID删除）")
	@SysLog("系统日志删除")
	@RequiresPermissions("sys:log:delete")
	@PostMapping("/delete")
	@ResponseBody
	public RestResponse deleteBatch(String[] ids) {
		sysLogService.deleteBatch(ids);
		return RestResponse.success();
	}
	
}
